package com.jjwxc.jwjskandriod.widget.dialog

import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.jjwxc.jwjskandriod.R
import com.jjwxc.jwjskandriod.framework.utils.FFUtils

class UpgradeVersionDialogFragment : BaseBottomDialogFragment() {
    private lateinit var llBottom: LinearLayout
    private lateinit var view: View
    private lateinit var btnConfirm: TextView
    private lateinit var btnCancel: TextView
    lateinit var confirmCallback: () -> Unit

    private var isShowCancelButton: Boolean = false

    override fun setContentViewID(): Int = R.layout.dialog_custom

    override fun findViewIDToOnClick() {
        llBottom = baseDialog.findViewById(R.id.ll_Bottom)
        view = baseDialog.findViewById(R.id.view)
        btnConfirm = baseDialog.findViewById(R.id.btn_confirm)
        btnCancel = baseDialog.findViewById(R.id.btn_cancel)

        btnConfirm.setOnClickListener {
//            dismissDialog()   // 该弹窗不允许取消
            if (::confirmCallback.isInitialized) {
                confirmCallback.invoke()
            }
        }

        btnCancel.setOnClickListener {
            dismissDialog()
        }

        if (!isShowCancelButton) {
            btnCancel.visibility = View.GONE
            view.visibility = View.GONE

            val layoutParams = llBottom.layoutParams
            layoutParams.width = FFUtils.dp2px(138F);

            llBottom.layoutParams = layoutParams
        }
    }

    /**
     * 設置類型
     * @param type true：顯示取消按鈕， false：不顯示取消按鈕
     */
    fun setShowCancel(type: Boolean) {
        this.isShowCancelButton = type
    }
}